﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServiceMapping.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines type
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Services.Mapping
{
    using System;
    using System.Diagnostics;

    using AutoMapper;

    using Hisaab.Services.Entities;

    /// <summary>
    /// Defines type <see cref="ServiceMapping"/>
    /// </summary>
    [DebuggerStepThrough]
    public class ServiceMapping : Profile
    {
        /// <summary>
        /// Configures this instance.
        /// </summary>
        protected override void Configure()
        {
            CreateMap<Business.Entities.Account, Account>()
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId))
                .ForMember(s => s.AccountType, o => o.MapFrom(d => d.AccountType))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId))
                .ForMember(s => s.InitialBalanceDate, o => o.MapFrom(d => d.InitialBalanceDate))
                .ForMember(s => s.InitialBalance, o => o.MapFrom(d => d.InitialBalance))
                .ForMember(s => s.AccountNumber, o => o.MapFrom(d => d.AccountNumber))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));
            CreateMap<Account, Business.Entities.Account>()
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId))
                .ForMember(s => s.AccountType, o => o.MapFrom(d => d.AccountType))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId))
                .ForMember(s => s.InitialBalanceDate, o => o.MapFrom(d => d.InitialBalanceDate))
                .ForMember(s => s.InitialBalance, o => o.MapFrom(d => d.InitialBalance))
                .ForMember(s => s.AccountNumber, o => o.MapFrom(d => d.AccountNumber))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            CreateMap<Business.Entities.AccountType, AccountType>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));
            CreateMap<AccountType, Business.Entities.AccountType>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            CreateMap<Business.Entities.Tag, Tag>()
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId));
            CreateMap<Tag, Business.Entities.Tag>()
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId));

            CreateMap<Business.Entities.Transaction, Transaction>()
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
                .ForMember(s => s.Amount, o => o.MapFrom(d => Math.Abs(d.Amount)))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
                .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType))
                .ForMember(s => s.LinkedTransactionAccount, o => o.Ignore())
                .ForMember(s => s.LinkedTransactionDate, o => o.Ignore())
                .ForMember(s => s.IsTransferTransaction, o => o.MapFrom(d => d.RelatedTransactionId > 0 ? true : false))
                .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId));

            CreateMap<Transaction, Business.Entities.Transaction>()
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
                .ForMember(s => s.Amount, o => o.MapFrom(d => Math.Abs(d.Amount)))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
                .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType))
                .ForMember(s => s.LinkedTransactionAccount, o => o.Ignore())
                .ForMember(s => s.LinkedTransactionDate, o => o.Ignore())
                .ForMember(s => s.IsTransferTransaction, o => o.MapFrom(d => d.RelatedTransactionId > 0 ? true : false))
                .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId));

            CreateMap<Business.Entities.Vehicle, Vehicle>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId));
            CreateMap<Vehicle, Business.Entities.Vehicle>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId));

            CreateMap<Business.Entities.VehicleTransaction, VehicleTransaction>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Milage, o => o.MapFrom(d => d.Milage))
                .ForMember(s => s.Fill, o => o.MapFrom(d => d.Fill))
                .ForMember(s => s.Oil, o => o.MapFrom(d => d.Oil))
                .ForMember(s => s.Notes, o => o.MapFrom(d => d.Notes))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Service, o => o.MapFrom(d => d.Service));
            CreateMap<VehicleTransaction, Business.Entities.VehicleTransaction>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Milage, o => o.MapFrom(d => d.Milage))
                .ForMember(s => s.Fill, o => o.MapFrom(d => d.Fill))
                .ForMember(s => s.Oil, o => o.MapFrom(d => d.Oil))
                .ForMember(s => s.Notes, o => o.MapFrom(d => d.Notes))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Service, o => o.MapFrom(d => d.Service));

            CreateMap<Business.Entities.AccountMonthlyTotal, AccountMonthlyTotal>()
                .ForMember(s => s.Month, o => o.MapFrom(d => d.Month))
                .ForMember(s => s.MonthlyTotal, o => o.MapFrom(d => d.MonthlyTotal))
                .ForMember(s => s.CumulativeTotal, o => o.MapFrom(d => d.CumulativeTotal));
            CreateMap<AccountMonthlyTotal, Business.Entities.AccountMonthlyTotal>()
                .ForMember(s => s.Month, o => o.MapFrom(d => d.Month))
                .ForMember(s => s.MonthlyTotal, o => o.MapFrom(d => d.MonthlyTotal))
                .ForMember(s => s.CumulativeTotal, o => o.MapFrom(d => d.CumulativeTotal));

            CreateMap<Business.Entities.User, User>()
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));
            CreateMap<User, Business.Entities.User>()
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            Mapper.AssertConfigurationIsValid();
        }
    }
}